<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <div id="app">
    <div ref="aa">通过 ref 获取DOM内的内容</div>
    <my-parent></my-parent>
  </div>
</body>
<template id="parent">
  <div>
    <h1>父组件</h1>
    <my-child ref="test"/>
  </div>
</template>
<template id="child">
  <div>
    <h4>子组件</h4>
  </div>
</template>
<script src="lib/vue.js"></script>
<script>
  // ref
  // 1. 在父组件调用子组件的地方，添加ref属性test，表示父组件可以通过 this.$refs.test 获取到子组件的实例
  // 2. 在HTML标签上添加 ref 属性 aa，可以用 this.$refs.aa 来表示获取DOM节点
  const Child = {
    template: '#child',
    data () {
      return {
        childMsg: 'child的msg'
      }
    },
    methods: {
      childFn () {
        console.log(this.childMsg)
      }
    }
  }
  const Parent = {
    template: '#parent',
    components: {
      MyChild: Child
    },
    mounted () {
      console.log(this.$refs.test.childMsg)
      this.$refs.test.childFn()
    }
  }

  new Vue({
    el: '#app',
    components: {
      MyParent: Parent
    },
    mounted () {
      console.log(this.$refs.aa.innerHTML)
    }
  })
</script>
</html>